let url = require("url");
let http = require("http");

let server = http.createServer();
server.on("request", (req, res) => {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end("11");

//   let tmp= url.parse("https://search.bilibili.com/all?vt=09511325&keyword=36%E6%B0%AA&from_source=webtop_search&spm_id_from=333.1007&search_source=3");
//   console.log(tmp.pathname);

  //     let urlObj = {
  //         protocol: 'http:',
  //         slashes: true,
  //         host: 'www.example.com',
  //         port: null,
  //         hostname: 'www.example.com',
  //         hash: '#hash',
  //         search: '?key=value',
  //         query: 'key=value',
  //         pathname: '/path',
  //         path: '/path?key=value',
  //         href: 'http://www.example.com/path?key=value#hash'
  //       };

  //       console.log(url.format(urlObj));

  // url.resolve('/one/two/three', 'four');         // '/one/two/four'
  // url.resolve('http://example.com/', '/one');    // 'http://example.com/one'
  // url.resolve('http://example.com/one', '/two'); // 'http://example.com/two'

    // 新版URL用法，前面为地址，后面为域名
    let myURL = new URL(req.url,"http://localhost:3000/");
    console.log(myURL);
//     URL {
//         href: 'http://localhost:3000/...',
//         origin: 'http://localhost:3000',
//         protocol: 'http:',
//         username: '',
//         password: '',
//         host: 'localhost:3000',
//         hostname: 'localhost',
//         port: '3000',
//         pathname: '/1654',
//         search: '',
//         searchParams: URLSearchParams {},
//         hash: ''
//       }
});

server.listen(3000, () => {
  console.log("server start on 3000 port");
});
